<!DOCTYPE html>
<html lang="zh-CN" data-i18n-page-title="profile">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>我的</title>
    <link rel="stylesheet" href="../css/style.css">
</head>
<body class="page">
    <div class="page-content">
        <div class="profile-header">
            <div class="avatar-container">
                <img src="../images/avatar.svg" alt="头像" class="avatar">
            </div>
            <h2 class="user-name">用户名</h2>
            <p class="user-title" data-i18n="job_intention">求职意向: 前端开发工程师</p>
        </div>
        
        <div class="profile-options">
            <div class="option-item" id="resumes-link">
                <img src="../images/resume.svg" alt="简历图标" class="option-icon">
                <span data-i18n="my_resumes">我的简历</span>
                <span class="option-arrow">›</span>
            </div>
            
            <div class="option-item" id="favorites-link">
                <img src="../images/favorite.svg" alt="收藏图标" class="option-icon">
                <span data-i18n="favorite_jobs">收藏职位</span>
                <span class="badge">3</span>
                <span class="option-arrow">›</span>
            </div>
            
            <div class="option-item" id="applications-link">
                <img src="../images/apply.svg" alt="申请图标" class="option-icon">
                <span data-i18n="my_applications">投递记录</span>
                <span class="badge">5</span>
                <span class="option-arrow">›</span>
            </div>
            
            <div class="option-item" id="settings-link">
                <img src="../images/setting.svg" alt="设置图标" class="option-icon">
                <span data-i18n="settings">设置</span>
                <span class="option-arrow">›</span>
            </div>
        </div>
        
        <div class="recent-activity">
            <h3 data-i18n="recent_activity">最近活动</h3>
            <div class="activity-item">
                <div class="activity-icon apply"></div>
                <div class="activity-content">
                    <p class="activity-title">投递了 "前端开发工程师" 职位</p>
                    <p class="activity-time">今天 14:30</p>
                </div>
            </div>
            
            <div class="activity-item">
                <div class="activity-icon view"></div>
                <div class="activity-content">
                    <p class="activity-title">浏览了 "UI设计师" 职位</p>
                    <p class="activity-time">昨天 09:15</p>
                </div>
            </div>
        </div>
    </div>

    <script src="../js/i18n.js"></script>
    <script src="../js/api.js"></script>
    <script>
        document.addEventListener('DOMContentLoaded', function() {
            // 初始化国际化
            if (window.i18n) {
                i18n.translatePage();
            }
            
            // 设置页面链接
            const settingsLink = document.getElementById('settings-link');
            if (settingsLink) {
                settingsLink.addEventListener('click', function() {
                    window.location.href = 'settings.html';
                });
            }
            
            // 其他选项的链接
            const resumesLink = document.getElementById('resumes-link');
            if (resumesLink) {
                resumesLink.addEventListener('click', function() {
                    window.location.href = 'resumes.html';
                });
            }
            
            const favoritesLink = document.getElementById('favorites-link');
            if (favoritesLink) {
                favoritesLink.addEventListener('click', function() {
                    window.location.href = 'favorites.html';
                });
            }
            
            const applicationsLink = document.getElementById('applications-link');
            if (applicationsLink) {
                applicationsLink.addEventListener('click', function() {
                    window.location.href = 'applications.html';
                });
            }
            
            // 加载用户资料
            async function loadUserProfile() {
                try {
                    // 检查是否已登录
                    if (!apiService.isLoggedIn()) {
                        window.location.href = 'login.html?redirect=' + encodeURIComponent(window.location.href);
                        return;
                    }
                    
                    // 获取用户资料
                    const profile = await apiService.getUserProfile();
                    
                    // 更新页面
                    document.querySelector('.user-name').textContent = profile.name;
                    if (profile.jobIntention) {
                        const jobIntentionElem = document.querySelector('.user-title');
                        jobIntentionElem.textContent = window.i18n ? 
                            i18n.t('job_intention') + ': ' + profile.jobIntention : 
                            '求职意向: ' + profile.jobIntention;
                    }
                    
                    // 如果有头像，更新头像
                    if (profile.avatar) {
                        document.querySelector('.avatar').src = profile.avatar;
                    }
                    
                    // 更新收藏和申请数量
                    if (profile.favoriteCount) {
                        document.querySelector('#favorites-link .badge').textContent = profile.favoriteCount;
                    }
                    
                    if (profile.applicationCount) {
                        document.querySelector('#applications-link .badge').textContent = profile.applicationCount;
                    }
                    
                } catch (error) {
                    console.error('加载用户资料失败:', error);
                }
            }
            
            // 加载用户资料
            loadUserProfile();
            
            // 监听语言变更事件
            window.addEventListener('message', function(event) {
                // 确保消息来源可信
                if (event.origin !== window.location.origin) return;
                
                // 处理语言变更消息
                if (event.data && event.data.type === 'language-change') {
                    const language = event.data.language;
                    
                    // 如果页面有i18n对象，应用语言变更
                    if (window.i18n) {
                        window.i18n.changeLanguage(language);
                    }
                }
            });
        });
    </script>
</body>
</html> 